package com.newppjoke.ktnewppjoke.utils;

import android.app.Application;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Project Name: ktnewppjoke
 * File Name:    AppGlobals.java
 * ClassName:    AppGlobals
 *
 * Description: TODO.
 *
 * @author My start
 * @date 2022年10月10日 7:24 下午
 *
 * Copyright (c) 2022年,  new Network CO.ltd. All Rights Reserved.
 */
public class AppGlobals
{
    private  static Application  sApplication;
    public static Application getApplication(){
        if (sApplication==null){
            try
            {
                Method method = Class.forName("android.app.ActivityThread")
                                                 .getDeclaredMethod("currentApplication");
                sApplication = (Application) method.invoke(null, null);
            }
            catch (NoSuchMethodException e)
            {
                e.printStackTrace();
            }
            catch (ClassNotFoundException e)
            {
                e.printStackTrace();
            }
            catch (InvocationTargetException e)
            {
                e.printStackTrace();
            }
            catch (IllegalAccessException e)
            {
                e.printStackTrace();
            }

        }

        return sApplication;

    }
}
